<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>

<%@ page import="java.util.Map" %>

<c:set var="formBean" value="${emProfMvBranchConditionEditForm}" />
<c:set var="formBeanMap" value="${formBean.map}" />

<c:set var="viewBean" value="${emProfMvBranchConditionEditView}" />
<c:set var="viewBeanMap" value="${viewBean.map}" />


<SCRIPT language='Javascript'>
  function cancelAction(theForm){
	window.location="<html-el:rewrite page="/em/cb/displayCriteriaBuilder.do"/>";
    return false;
  }

  <c:choose>
    <c:when test='${formBeanMap.actType == "create"}'>
      function loadCalculationPage( url ) {
        var newLoc = "<html-el:rewrite page="/em/cb/profMvAggrConditionEdit.do" paramId="key" paramName="formBean" paramProperty="key"/>";
        newLoc += "&actType=create";
        window.location = newLoc;
        return false;
      }
    </c:when>
    <c:otherwise>
      function doneClicked(theForm) {
        theForm.action = "<html-el:rewrite page="/em/cb/profMvBranchConditionUpdate.do"/>";
        theForm.submit();
        return false;
      }
    </c:otherwise>
  </c:choose>

</SCRIPT>

<html-el:form action="/em/cb/profMvBranchConditionNewNext.do">
  <html-el:hidden property="key" />
  <html-el:hidden property="actType" />
  <c:set var="pageTitle">
    <c:choose>
      <c:when test='${formBeanMap.actType == "create"}'>
        <bean-el:message bundle="em" key="em.cb.multivalue.branch.create" />
      </c:when>
      <c:otherwise>
        <bean-el:message bundle="em" key="em.cb.multivalue.branch.edit" />
      </c:otherwise>
    </c:choose>
  </c:set>
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle"><c:out value="${pageTitle}" /></div>
      <div class="errorMessage"><html-el:errors/></div>

      <!--end page title area here-->

      <div class="pageSubtitle">
        <span class="left"><c:out value="${pageTitle}" /></span>
        <span class="right">
          <c:if test='${formBeanMap.actType == "create"}'>
            <input type="button" value="<bean-el:message bundle="em" key="em.cb.multivalue.branch.create.aggr.condition"/>" class="inputButton" onclick="javascript:loadCalculationPage()"/>
          </c:if>
        </span>
      </div>
      <div class="pageInstructions"></div>

      <!--start main content here-->
      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class="labelField">
            <c:set var="aggregatorSelectList">
              <html-el:select property="isPositive" size="1">
                <html-el:option value="true">
                  <bean-el:message bundle="em" key="em.cb.multivalue.branch.options.hasAnEntry"/>
                </html-el:option>
                <html-el:option value="false">
                  <bean-el:message bundle="em" key="em.cb.multivalue.branch.options.notHasAnEntry"/>
                </html-el:option>
              </html-el:select>
            </c:set>
            <bean-el:message bundle="em" key="em.cb.multivalue.branch.prompt" arg0="${aggregatorSelectList}" arg1="${viewBeanMap.friendlyName}" /> 
          </td>
        </tr>
      </table>

      <div class="pageButtonWrap" align="right">
        <input type="button" name="cancelBtn" value="<bean-el:message bundle="em" key="button.cancel"/>" class="inputButton" onclick="javascript:cancelAction(this.form)">
        <c:choose>
          <c:when test='${formBeanMap.actType == "create"}'>
            <%-- 
              The following two hidden fields are for the page after clicking continue button.
              So the next page can show a "Back" button if fromBranchNew is true, and when the 
              user clicks that "Back" button, it will knows which page to go. And since we set
              the form bean to session scope for branch condition creation, when it comes to 
              this page again, the modification will still be there.
            --%>
            <input type="hidden" name="fromBranchNew" value="true">
            <input type="hidden" name="backURL" value="<html-el:rewrite page="/em/cb/profMvBranchConditionEdit.do" />" >

            <input type="submit" name="ContinueBtn" value="<bean-el:message bundle="em" key="emarketing.criteriaBuilder.genericListCondition.button.continue"/>" class="inputButton">
          </c:when>
          <c:otherwise>
            <input type="button" name="doneBtn" value="<bean-el:message bundle="em" key="button.done"/>" class="inputButton" onclick="JavaScript:return doneClicked(this.form);">
          </c:otherwise>
        </c:choose>
      </div>
    </td>
  </tr>
</table>
</html-el:form>

